import subprocess
import IPy
from IPy import IP
ip = IP('192.168.0.0/24')
# print(ip.len())
with open('ip1.txt','w',encoding = 'utf-8') as f:
    for x in ip:
    # 	print(x)
        res = subprocess.getstatusoutput("ping -c 1 {}".format(x))
        #res = subprocess.getstatusoutput(['ping','-c','1','x'])
        if res[0] == 0:
            jieguo = "{}已被使用".format(x)
            print(jieguo)
            f.write(jieguo+'\n')
        elif res[0] == 1:
            print('{}没有存活'.format(x))
